package com.onlinemusic.controller;

import com.onlinemusic.common.R;
import com.onlinemusic.pojo.request.SingerRequest;
import com.onlinemusic.service.SingerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("singer")
public class SingerController {
    @Autowired
    private SingerService singerService;

    /**
     * 添加歌手
     * @param addSingerRequest
     * @return
     */
    @PostMapping("add")
    public R addSinger(@RequestBody SingerRequest addSingerRequest) {
        return singerService.addSinger(addSingerRequest);
    }

    /**
     * 删除歌手
     * @param id
     * @return
     */
    @DeleteMapping("delete")
    public R deleteSinger(@RequestParam int id) {
        return singerService.deleteSinger(id);
    }

    /**
     * 批量删除用户
     *
     * @param id
     * @return
     */
    @DeleteMapping("deleteIds")
    public R deleteSingers(@RequestParam String[] id) {
        return singerService.deleteSingers(id);
    }

    /**
     * 更新歌手信息
     * @param updateSingerRequest
     * @return
     */
    @PostMapping("update")
    public R updateSingerMsg(@RequestBody SingerRequest updateSingerRequest) {
        return singerService.updateSingerMsg(updateSingerRequest);
    }

    /**
     * 更新头像
     * @param avatarFile
     * @param id
     * @return
     */
    @PostMapping("avatar/update")
    public R updateSingerPic(@RequestParam("file") MultipartFile avatarFile, @RequestParam("id") int id) {
        return singerService.updateSingerPic(avatarFile, id);
    }

    /**
     * 获取所有歌手 用于客户端展示
     * @return
     */
    @GetMapping
    public R allSinger() {
        return singerService.allSinger();
    }

    /**
     * 根据姓名查找歌手
     * @param name
     * @return
     */
    @GetMapping("name/detail")
    public R singerOfName(@RequestParam String name) {
        return singerService.singerOfName(name);
    }

    /**
     * 根据性别查找歌手
     * @param sex
     * @return
     */
    @GetMapping("sex/detail")
    public R singerOfSex(@RequestParam int sex) {
        return singerService.singerOfSex(sex);
    }
}
